package cn.mulanbay.api.system.service;

import cn.mulanbay.api.system.bean.RemoteCreateWxUser;
import cn.mulanbay.api.system.config.FeignRequestInterceptor;
import cn.mulanbay.api.system.factory.RemoteUserFallbackFactory;
import cn.mulanbay.business.bean.LoginUser;
import cn.mulanbay.business.bean.UserLoginInfo;
import cn.mulanbay.common.config.ServiceNameConstants;
import cn.mulanbay.common.domain.R;
import cn.mulanbay.persistent.entity.User;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 用户服务
 *
 * @author fenghong
 */
@FeignClient(contextId = "remoteUserService",
        value = ServiceNameConstants.ADMIN_API_SERVICE,
        fallbackFactory = RemoteUserFallbackFactory.class,
        configuration={FeignRequestInterceptor.class})
public interface RemoteUserService {

    /**
     * 通过用户编号查询用户信息
     *
     * @param id 用户编号
     * @return 结果
     */
    @GetMapping(value = "/user/get")
    public R<User> getUser(@RequestParam("id") Long id);

    /**
     * 通过用户名查询用户信息
     *
     * @param username 用户名称
     * @return 结果
     */
    @GetMapping(value = "/user/getByUsername")
    public R<User> getUserByUsername(@RequestParam("username") String username);

    /**
     * 获取用户角色编号
     *
     * @param userId
     * @return
     */
    @GetMapping(value = "/user/getRoleId")
    public R<Long> getRoleId(@RequestParam("userId") Long userId);

    /**
     * 通过最后一次登录token获取用户
     *
     * @param loginToken
     * @return
     */
    @GetMapping(value = "/user/loadLoginUser")
    public R<LoginUser> loadLoginUser(@RequestParam("loginToken")String loginToken);

    /**
     * 更新用户登录信息
     *
     * @param uli 用户登录信息
     * @return 结果
     */
    @PostMapping("/user/updateLoginInfo")
    public R<Boolean> updateLoginInfo(@RequestBody UserLoginInfo uli);

    /**
     * 创建微信用户
     * @param cw
     * @return
     */
    @PostMapping("/user/createWxUser")
    public R<Long> createWxUser(@RequestBody RemoteCreateWxUser cw);

}
